package com.zhanghe.mall.web.controller;

import com.zhanghe.mall.service.AttributePropertyService;
import com.zhanghe.mall.service.dto.AddAttributePropertyDTO;
import com.zhanghe.mall.web.po.AddAttributePropertyPO;
import com.zhanghe.mall.web.util.R;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class AttributePropertyController {

  @Autowired
  private AttributePropertyService attributePropertyService;

  /**
   * 添加商品分类属性的值
   * @param classificationAttributeId
   * @param addAttributePropertyPO
   * @return
   */
  @PostMapping("/classification/attribute/{classificationAttributeId}/property")
  public R insert(@PathVariable Long classificationAttributeId,AddAttributePropertyPO addAttributePropertyPO){
    AddAttributePropertyDTO addAttributePropertyDTO = new AddAttributePropertyDTO();
    BeanUtils.copyProperties(addAttributePropertyPO,addAttributePropertyDTO);
    addAttributePropertyDTO.setClassificationAttributeId(classificationAttributeId);
    attributePropertyService.insert(addAttributePropertyDTO);
    return new R(1);
  }

}
